/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

#ifndef Scenic_Renderer_Context_h
#define Scenic_Renderer_Context_h


#include "Tesselator.h"
#include "Primitives.h"


namespace Scenic 
{ 
namespace Renderer
{

class Surface;
class Texture;
class PolygonRenderer;
class LineRenderer;
class Primitives;
class ScenePrimitives;
class FilterKernel;


class ClipArea
{
public:
	ClipArea();
	~ClipArea();

	ClipArea *parent;
	int x;
	int y;
	int width;
	int height;
	int offsetX;
	int offsetY;
	int type;
	Surface *surface;
	Texture *texture;
	int textureWidth;
	int textureHeight;
	bool linearColorSpace;

	int getModulation();
};

class Context : public Resource
{
	Surface *originalRenderTarget;
	bool insideScene;
public:
	Canvas *canvas;
	Image *image;
	Device *device;
	int width;
	int height;

	bool polygonAntialias;
	FilterKernel *filterKernel;
	double filterWidth;
	double filterHeight;

	Affine2 transform;
	RGBAFloat color;

	VertexStore *glyphVs;

	PolygonRenderer *polygonRenderer;
	Texture *aaPolygonTexture;

	float lineWidth;
	int lineCap;
	int lineJoin;
	float miterLimit;
	DynArray<double> lineDashLengths;
	double lineDashPhase;
	LineRenderer *lineRenderer;

	ClipArea *clip;

	Primitives *primitives;
	ScenePrimitives scenePrimitives;

	Context(Canvas *canvas);
	Context(Image *image);
	~Context();

	bool beginScene();
	void endScene();

	void freeDeviceResources();
	void setPrimitives(Primitives *p);
	void setRenderTarget(Surface *target);
	void initializeViewport(int width, int height);
private:
	void init();
};

Context *getContext(int id);

}
}

#endif
